package com.atguigu.service.impl;

import com.atguigu.base.BaseMapper;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.entity.UserFollow;
import com.atguigu.entity.vo.UserFollowVo;
import com.atguigu.mapper.UserFollowMapper;
import com.atguigu.service.UserFollowService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserFollowServiceImpl extends BaseServiceImpl<UserFollow> implements UserFollowService {

    @Autowired
    private UserFollowMapper userFollowMapper;

    @Override
    public BaseMapper<UserFollow> getBaseMapper() {
        return userFollowMapper;
    }

    @Override
    public void deleteByUserIdAndHouseId(Long userInfoId, Long houseId) {
        userFollowMapper.deleteByUserIdAndHouseId(userInfoId,houseId);
    }

    @Override
    public PageInfo<UserFollowVo> findByPage(Integer pageNum, Integer pageSize, Long userId) {
        PageHelper.startPage(pageNum, pageSize);
        Page<UserFollowVo> page = userFollowMapper.findListPage(userId);
        return new PageInfo<UserFollowVo>(page);
    }

    @Override
    public void cancelFollowByKey(Long id) {
        userFollowMapper.deleteByKey(id);
    }
    @Override
    public boolean isFollow(Long userInfoId, Long houseId) {
        UserFollow userFollow = userFollowMapper.getByUserIdAndHouseId(userInfoId,houseId);
        //通过userInfoId,houseId能否查到数据,如果有说明已关注,如果没说明没关注
        return userFollow!=null;
    }

}
